import {allpageList} from '../../../server/api'
import {openMap} from '../../../server/pulbmethod'
import {removeImageTags} from '../../../server/shake'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hdname:'',
    active:'0',
    list:[],
    pageNo:1,
    pageSize:10,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({list:[],pageNo:1,pageSize:10})
    this.getdata()
  },
  async getdata(val){
    const params = {
        pageNo:val == undefined ? this.data.pageNo : val.pageNo,
        pageSize:val == undefined ? this.data.pageSize : val.pageSize,
        ueStatus:this.data.active,
        title:this.data.hdname
    }
      const res = await allpageList(params)
      if(res.code == 200)
      {
        const  value = res.result.records.map((item)=>{
         item.remark = removeImageTags(item.remark).length > 30 ? (removeImageTags(item.remark)).slice(0,30) + '.....' :  removeImageTags(item.remark)
         return item
        })
        this.setData({list:val == undefined ? value : [...this.data.list,...value]})
      }
  },
  //搜索活动
  searchdata(){
    this.setData({list:[],pageNo:1,pageSize:10})
    this.getdata()
  },
  onChange(e){
    const index = e.detail.name
    this.setData({list:[],pageNo:1,pageSize:10,active:index})
    this.getdata()
  },
  //详情
  detial(e)
  {
    const val = e.currentTarget.dataset.obj
    const obj = encodeURIComponent(JSON.stringify(val))
    wx.navigateTo({
      url: `../../../subPackagesB/pages/eventdetail/eventdetail?obj=${obj}`,
    })
  },
  getMore(){
    this.data.pageNo++
    const params = {
      pageNo:this.data.pageNo,
      pageSize:this.data.pageSize
    }
    this.getdata(params)
  },
  //打开地图
  openadd(e){
    const obj = e.currentTarget.dataset.obj
    console.log(obj,'obj');
    openMap(obj)
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})